import pako from "pako";

export function compressBase64(base64) {
    // 将 Base64 转换为二进制字符串
    const binaryString = atob(base64.split(",")[1]);
    const binaryArray = new Uint8Array(binaryString.length);
    for (let i = 0; i < binaryString.length; i++) {
        binaryArray[i] = binaryString.charCodeAt(i);
    }

    // 使用 pako 压缩
    const compressed = pako.gzip(binaryArray);

    // 将压缩后的数据转换回 Base64
    const compressedBase64 = btoa(
        String.fromCharCode.apply(null, new Uint8Array(compressed))
    );

    return compressedBase64;
}
